import Request from 'luch-request'; // 使用npm

const http = new Request(
    {
        // baseURL: 'http://localhost:8080',
        baseURL: 'https://vue.bigtian.club/prod-api/',
        timeout: 10000,
    }
);
http.interceptors.request.use((config) => {
    // uni.setStorageSync('token', res.data);
    const token = uni.getStorageSync('token')
    if (token) {
        config.header.Authorization = `${token}`;
    }
    return config
})

http.interceptors.response.use((res) => {
    // 如果是 ArrayBuffer 类型，直接返回数据
    if (res.config?.responseType === 'arraybuffer') {
        return res.data;
    }
    let result = res.data
    if (result.code === 200) {
        return result
    }

    uni.showToast({
        title: result.msg,
        icon: 'error'
    })
})

export default http;
